package baitap_Canban;
 
import java.util.Scanner;
 
/**
*
* @author BiBom
*/
public class Phanso_Demo {
  //tinh tong, hieu, thuong, tich
    int ts,ms;
    Phanso_Demo(){}
    Scanner input = new Scanner(System.in);
    public void inpudata(){
        System.out.print("Nhap Tu so: ");
        this.ts = input.nextInt();
        while(ms == 0){
        System.out.print("Nhap Mau so: ");
        this.ms = input.nextInt();
        }
    }
    public int UCLN(int a,int b){
        if(a==0||b==0)
            return a+b;
        while(a!=b){
            if(a>b)
                a = a - b;
            else
                b = b - a;
        }
        return a;
    }
    public void T_Gian(){
        int i = UCLN(ts, ms);
        this.ts = this.ts/i;
        this.ms = this.ms/i;
    }
    public Phanso_Demo Tong(Phanso_Demo f){
        Phanso_Demo ps = new Phanso_Demo();
        ps.ts = this.ts*f.ms+f.ts*this.ms;
        ps.ms = this.ms*f.ms;
        ps.T_Gian();
        return ps;
    }
    public Phanso_Demo Hieu(Phanso_Demo f){
        Phanso_Demo ps = new Phanso_Demo();
        ps.ts = this.ts*f.ms - f.ts*this.ms;
        ps.ms = this.ms*f.ms;
        ps.T_Gian();
        return ps;
    }
    public Phanso_Demo Tich(Phanso_Demo f){
        Phanso_Demo ps = new Phanso_Demo();
        ps.ts = this.ts*f.ts;
        ps.ms = this.ms*f.ms;
        ps.T_Gian();
        return ps;
    }
    public Phanso_Demo Thuong(Phanso_Demo f){
        Phanso_Demo ps = new Phanso_Demo();
        ps.ts = this.ts*f.ms;
        ps.ms = f.ts*this.ms;
        ps.T_Gian();
        return ps;
    }
    public void outputdata(String y){
        if(ts!=ms){
            if(ts!=0)
            System.out.println(y+" "+ts+"/"+ms);
            else
                System.out.println(y+" 0");
        }else System.out.println(y+" 1");
    }
  public static void main(String[] args) {
        Phanso_Demo ps1 = new Phanso_Demo();
        Phanso_Demo ps2 = new Phanso_Demo();
        System.out.println("Phan So 1.");
        ps1.inpudata();
        System.out.println("Phan So 2.");
        ps2.inpudata();
        ps1.Tong(ps2).outputdata("Tong 2 Phan So =");
        ps1.Hieu(ps2).outputdata("Hieu 2 Phan So =");
        ps1.Tich(ps2).outputdata("Tich 2 Phan So =");
        ps1.Thuong(ps2).outputdata("Thuong  2 Phan So =");
    }
}